<template>
	<view class="afterSale">
		<view class="con" v-for="(item,index) in pageResult.list" :key="index">
			<view class="title">
				<view>{{item.sn}}</view>
				<view class="tc">{{item.create_time}}</view>
				<view class="tc">{{item.refund_type}}</view>
				<view class="tr status">{{item.refund_status_name}}</view>
			</view>
			<view class="goods" >
				<image :src="item.product_picture" mode="aspectFill"></image>
				<view class="right">
					<text>{{item.product_name}}</text>
					<view class="num">
						<text>{{item.sku_name}}</text>
						<text>x{{item.product_num}}</text>
					</view>
					<text>{{item.price > 0 ? '￥'+item.price : ''}}{{item.price > 0 && item.point > 0 ? ' + ' : ''}}{{item.point > 0 ? item.point+'豆力' : ''}}</text>
				</view>
			</view>
			<view class="bottom" v-if="item.button_list.length > 0">
				<view :class="index2 == 0 ? 'state' : 'state1'" v-for="(button,index2) in item.button_list" :key="index2" @click="operate(button.type, index)">{{button.name}}</view>
			</view>
		</view>
		<view v-if="pageResult.list.length == 0" class="nocontent">
			<image :src="obtainImgUrl('icon/noItem.png')" mode="widthFix"></image>
			<text>您暂未有售后订单～</text>
		</view>
	</view>
</template>

<script>
	import serve from '../../static/request.js';
	import storage from '../../static/appkey.js';
	import common from '../../static/jump.js';
	export default {
		data() {
			return {
				pageParam: {
					page: 0,
				},
				pageResult: {
					list: [],
					isEmpty: false,
					isEnd: false
				}
			}
		},
		methods: {
			getList(){
				var self = this;
				self.pageParam.page++
				serve.request({
					url: '/member/order-customer/index',
					data: self.pageParam
				}).then(res => {
					console.log(res.data); 
					if (res.data && res.data.length > 0) {
						self.pageResult.list=self.pageResult.list.concat(res.data);
					}
					self.pageResult.isEmpty = self.pageResult.list.length == 0;
					self.pageResult.isEnd = res.data.length == 0; 
				});
			},
			operate(operateType, key) {
				var self = this;
				let operateId = self.pageResult.list[key].id;
				if(operateType == 'refund_close') {
					uni.showModal({
					    title: '提示',
					    content: '您确定取消该售后申请吗',
					    success: function (res) {
					        if (res.confirm) {
					            serve.request({
									url: '/member/order-customer/refund-close',
									data:{
										id:operateId,
									}
								}).then(res => {
									uni.showToast({
										title:res.message,
										icon: 'none',
									});
									if(res.code == 200) {
										self.pageResult.list[key].refund_status_name = "已取消";
										self.pageResult.list[key].button_list = [
											{'type': 'refund_view', 'name' : '查看详情'}
										];
									} 
								});
					        } 
					    }
					});
					return ;
				} else if(operateType == 'refund_product') {
					uni.navigateTo({
						url:'/pages/my/refund?id=' + operateId
					});
					return ;
				} else if(operateType == 'refund_view') {
					uni.navigateTo({
						url:'/pages/my/saleDatails?id=' + operateId
					});
					return ;
				} else if(operateType == 'refund_delivery') {
					uni.showModal({
					    title: '提示',
					    content: '您确定换货商品已收货吗',
					    success: function (res) {
					        if (res.confirm) {
					            serve.request({
									url: '/member/order-customer/refund-delivery',
									data:{
										id:operateId,
									}
								}).then(res => {
									uni.showToast({
										title:res.message,
										icon: 'none',
									});
									if(res.code == 200) {
										self.pageResult.list[key].refund_status_name = "已完成";
										self.pageResult.list[key].button_list = [
											{'type': 'refund_view', 'name' : '查看详情'}
										];
									} 
								});
					        } 
					    }
					});
					return ;
				}
			},
			obtainImgUrl(imgUrl) {
				return serve.imgUrl()+imgUrl;
			},
			jump(jump_type, jump_link){
				if(jump_type == 'refund_colse') {
					this.operate(jump_type, jump_link);
					return ;
				}
				common.jump(jump_type, jump_link);
			}
		},
		onLoad(option) {
			this.getList();
		},
		onPullDownRefresh() {
			this.pageParam.page=0;
			this.pageResult.list=[];
			this.getList();
		},
		onReachBottom() {
			if(this.pageResult.isEnd ||this.pageResult.isEmpty){
				return
			}
			this.getList()
		}
	}
</script>

<style scoped lang="scss">
	.afterSale{
		width: 100%;
		min-height: 100vh;
		.con{
			
			border-bottom: 16upx rgba(252,252,253,1) solid;
			padding: 20rpx;
			.title{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				padding-bottom: 10rpx;
				box-sizing: border-box;
				border-bottom: 1upx rgba(235,236,240,1) solid;
				font-size:28upx;
				font-weight:bold;
				view {
					width: 25%;
				}
				.tc {
					text-align: center;
				}
				.tr {
					text-align: right;
					padding-right: 10rpx;
				}
			}
			.goods{
				display: flex;
				align-items: center;
				box-sizing: border-box;
				padding: 30upx;
				width: 100%;
				border-bottom: 1upx rgba(235,236,240,1) solid;
				image{
					width:170upx;
					height:170upx;
				}
				.right{
					width: 505upx;
					display: flex;
					margin-left: 17upx;
					flex-direction: column;
					justify-content: center;
					font-size:24upx;
					color:rgba(255,198,0,1);
					text:first-child{
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						font-size: 32upx;
						font-weight:bold;
						color:rgba(60,72,104,1);
					}
					.num{
						display: flex;
						justify-content: space-between;
						padding: 26upx 0upx;
						color:rgba(60,72,104,0.5);
						text:first-child{
							font-size: 24upx;
							font-weight:400;
							color:rgba(60,72,104,0.5);
						}
					}
				}
			}
			.bottom{
				display: flex;
				box-sizing: border-box;
				justify-content: flex-end;
				padding: 25upx 30upx;
				.state{
					padding: 18upx 76upx;
					background:rgba(255,255,255,1);
					border:1px solid rgba(60,72,104,0.1);
					font-size:24upx;
					color:rgba(60,72,104,0.6);
					margin-left: 13upx;
				}
				.state1{
					padding: 18upx 76upx;
					background:rgba(255,255,255,1);
					border:1px solid rgba(60,72,104,0.1);
					font-size:24upx;
					color:rgba(60,72,104,1);
					margin-left: 13upx;
				}
			}
		}
		.nocontent{
			width: 100%;
			padding-top: 338upx;
			display: flex;
			flex-direction: column;
			align-items: center;
			image{
				width:220upx;
				height:124upx;
			}
			text{
				font-size:28upx;
				color:rgba(204,204,204,1);
			     margin-top: 30upx;
			}
		}
	}
</style>
